import {format} from "@/ts/Utils"

/**
 * 用户
 */
export class User {
    /**
     * ID
     */
    public id: Number;
    /**
     * 邮箱
     */
    public email: string;
    /**
     * 用户名
     */
    public userName: string;
    /**
     * 昵称
     */
    public nickName: string;
    /**
     * 手机号
     */
    public phone: string;

    /**
     * 密码
     */
    public tcode: string;

    /**
     * 验证码
     */
    public code: string;

    public accountPassed: boolean;

    public phonePassed: boolean;

    public userNamePassed: boolean;

    public emailPassed: boolean;

    public passwordPassed: boolean;

    public codePassed: boolean;

    /**
     * 判断是否是一个账号
     * 判断userName 是否符合用户名/手机号/邮箱的格式
     * @returns
     */
    validateAccount(): boolean {
        return format.isUserName(this.userName) || format.isEmail(this.userName) || format.isPhone(this.userName)
    }

    validateUserName(): boolean {
        return format.isUserName(this.userName);
    }

    validatePhone(): boolean {
        return format.isPhone(this.phone);
    }

    validateEmail(): boolean {
        return format.isEmail(this.email);
    }

    validatePassword(): boolean {
        return format.isPassword(this.tcode);
    }

    validateCode(): boolean {
        return format.isCode(this.code);
    }

    constructor() {
        this.id = 0;
        this.email = "";
        this.userName = "";
        this.nickName = "";
        this.phone = "";
        this.tcode = "";
        this.code = "";
        this.emailPassed = true;
        this.codePassed = true;
        this.passwordPassed = true;
        this.userNamePassed = true;
        this.phonePassed = true;
        this.accountPassed = true;
    };
}


/**
 * 登录用户
 */
export class AuthUser {
    /**
     * 用户ID
     */
    userId = 0;
    /**
     * 用户名
     */
    userName = "";
    /**
     * 昵称
     */
    nickName = "";
    /**
     * 角色Id
     */
    roleId = 0;
    /**
     * 角色名
     */
    roleName = "";
    token = "";
    phone = "";
    email = "";
    /**
     * 权限ID列表
     */
    rights = [];
    buttons:String[] = [];

    loginFlag = false;

    constructor() {
    }
}